<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.dianbo.bean.*,com.dianbo.dao.*,com.UserModule.bean.*"%>  
<%@ page import="util.*" %>
<%
List<Dianbo> dianboList =new ArrayList();
    if(request.getParameter("s")!=null)
    	dianboList=(ArrayList) session.getAttribute("dianboList");
    String content=session.getAttribute("content").toString();
    String selectdianbotype=session.getAttribute("selectdianbotype").toString();
	  //---------分页
	    int currentPage=1;
	    if(request.getParameter("Page")!=null)
	    {
	    	dianboList=(ArrayList) session.getAttribute("dianboList");
	    	currentPage=Integer.parseInt(request.getParameter("Page"));
	    }
	//System.out.println("size==" + SmsTemplateList.size());
%>
<jsp:include page="../head.jsp"></jsp:include>
<body>
<div id="pager">
<jsp:include page="../top.jsp"><jsp:param name="topCurrent" value="2" /></jsp:include>    
<jsp:include page="Left.jsp">
<jsp:param name="um" value="12" /></jsp:include> 
		<section id="container">
        <div id="crumbs">
        	点播资源库 &raquo; 点播列表
        </div>
    <div id="main">
			<div class="tabs">
				<ul class="tabs-nav clearfix">
					<li>
						点播列表
					</li>
					<li>
						导入点播信息
					</li>
					<li>
						新增点播信息
					</li>
				</ul>
				<div class="tabs-panel">
			<%
			try{
		 	 String resultSM=session.getAttribute("resultSM").toString();
			 if(!resultSM.equals("")){
				 out.println("<script>alertmess('"+resultSM+"');</script>");
				 session.removeAttribute("resultSM");
			 }
			 }catch(Exception ex){
			 
			 }
		 	%>
				 <form action="" method="post" id="form1" name="form2">
					<table width="100%" class="datalist">
						<thead>
						<tr>
								<th colspan="7" class="tl">
								                                       点播类型
												<select id="dianbotype" name="dianbotype">
													<option value="0">
													请选择
													</option>
													 <%
													 TbUserBean user = (TbUserBean)request.getSession().getAttribute("User");
													 List list = new AllTypeList().getLastValue(user.getUserId());
													 List<DianboType> dianboTypeList = (ArrayList<DianboType>)list.get(0);
													 if(dianboTypeList!=null&&dianboTypeList.size()>0){
													for(int t=0;t<dianboTypeList.size();t++){
														DianboType diaobotype=dianboTypeList.get(t);
													%>
													<option value="<%=diaobotype.getTypeId() %>"
													<%
													if(selectdianbotype.equals(diaobotype.getTypeId())){
														%>
														selected="selected"
													<%}
													%>
													>
													  <%=diaobotype.getTypeName() %>
													</option>
														<%
													}	 }
													 %>
												
												</select>
												内容
												<input type="text" id="content" name="content"   value="<%=content %>" />
												<input type="button" value="查询" onclick="searcherByDianbo('../DianboServlet?method=looksearch')" />&nbsp;&nbsp;
												<input type="button" value="批删" onclick="deleteSmsAllSM('deleteAll','../DianboServlet?method=deleteAll&content=<%=content %>&dianbotype=<%=selectdianbotype %>')" />&nbsp;&nbsp;
											    <input type="button" value="导出" onclick="window.location='../upload/export3.xls'" />
											     
								</th>
							</tr>
							<tr>
								<td class="tc">
									<input type="checkbox" title="全选" onClick="check_allSM('deleteAll')"/>
								</td>
								<td width="4%">
									序号
								</td>
								<td width="6%">
									点播类型
								</td>
							    <td width="60%">
									点播内容
								</td>
								<td width="10%">
									上传号码
								</td>
								<td width="12%">
									创建时间
								</td>
								<td width="8%">
									操作
								</td>
							</tr>
							
						</thead>
						<%
						if(dianboList!=null){
							String[][] exportArray=new String[dianboList.size()+1][4];
							exportArray[0][0]="点播类型";
				        	exportArray[0][1]="点播内容";
				        	exportArray[0][2]="上传号码";
				        	exportArray[0][3]="创建时间";
				        	for(int rowIndex=1;rowIndex<dianboList.size()+1;rowIndex++)
				        	{
				        		    Dianbo db=dianboList.get(rowIndex-1);
				        			exportArray[rowIndex][0]=""+new DianboTypeDao().getDianboType(db.getTypeId());
				        			exportArray[rowIndex][1]=""+db.getQsContent();
				        			if(db.getQsUpPhone()==null){
				        				exportArray[rowIndex][2]="";
				        			}else{
				        				exportArray[rowIndex][2]=""+db.getQsUpPhone();
				        			}
				        			exportArray[rowIndex][3]=""+db.getQsUpTime().substring(0,19);
				        	}
				        	FileOperate.setExcelSavePath(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
				        	FileOperate.deleteFile(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
				        	FileOperate.writeExcel(exportArray);
							int i=0;  
							//--------------分页
							MyPagination mPage=new MyPagination();
							dianboList=mPage.getInitPage(dianboList,currentPage,10);
							if (dianboList != null && dianboList.size() > 0) {
											
							for (Dianbo dianboBean : dianboList) {
								System.out.println(dianboBean.getTypeId()+"||"+dianboBean.getQsContent());
								
							i++;
						%>
						<tr>
							<td class="tc">
								<input name="deleteAll" id = "deleteAll" type="checkbox" value="<%=dianboBean.getQsInfoId()%>"/>
							</td>
				  			 <td><%=((10*(currentPage-1))+i) %></td>
							<td><%=new DianboTypeDao().getDianboType(dianboBean.getTypeId()).getTypeName()%></td>
							  <script type="text/javascript">
								$(function(){
					 				$('#demo-basic<%=i%>').poshytip();
								
					   			})
				  			 </script>
							<td><a id="demo-basic<%=i%>" title="<%=dianboBean.getQsContent()%>"><%=new UtilDAO().sub_String(dianboBean.getQsContent())%></a></td>
							<%
							if(dianboBean.getQsUpPhone()==null || dianboBean.getQsUpPhone().equals("")){
		        				 %>
		        				 <td>人工录入</td>
		        				 <%
		        			}else{
		        				%>
		        				<td><%=dianboBean.getQsUpPhone() %></td>
		        				<%
		        			}
							%>
							<td><%=dianboBean.getQsUpTime().substring(0,19)%></td>
							<td class="tc">
							    
								<a title="删除该记录" class="duanyu_del" style="cursor:hand" onClick="deleteOneSM('../DianboServlet?method=deleteOne&qsInfoId=<%=dianboBean.getQsInfoId() %>&content=<%=content %>&dianbotype=<%=selectdianbotype %>')">删除</a>
							</td>
						</tr> 
					   <%
					   }
					   }
					   
					   %>
					   <%=mPage.printCtrl("hudong/dianboList.jsp",currentPage,"&content="+content+"&selectdianbotype="+selectdianbotype) %>
						<%}
						else{
											    String[][] exportArray=new String[1][4];
										      	exportArray[0][0]="手机号码";
									        	exportArray[0][1]="创建人";
									        	exportArray[0][2]="创建时间";
									 			FileOperate.setExcelSavePath(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
									        	FileOperate.deleteFile(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
									        	FileOperate.writeExcel(exportArray);
					        	
											}
						%>
					</table>
				</form>
				</div>
				<div class="tabs-panel">
				    <form id="formimport" name="formimport" enctype="multipart/form-data"  method="post" action="">
                	<table width="100%" class="datalist">
                	<tr>
                	<td class="tc">导入模版：</td>
                	<td>
                	    <a href="./module/dianbo.xls" >点击这里下载导入模板</a>
                	</td>
                	</tr>
                      <tr>
                        <td  class="tc">导入点播信息：</td>
                        <td>
                           <input  type="file" id="daoru" name="daoru" />
                        </td>
                        </tr>
                        <tr>
                        <th scope="row"></th>
                        <td><input type="button" onclick="insertImport()" value=" 提  交 " /></td>
                        	<script type="text/javascript">
                        	//验证上传格式
                        	function insertImport(){
                        			var fileName = document.getElementById("daoru").value;
                        			var lastFileName = encodeURI(fileName);
                        			lastFileName = encodeURI(lastFileName);
                        			 var file_Name = fileName.split(".")[fileName.split(".").length-1];
                        			if(file_Name=="xls"||file_Name=="XLS")
                        			{
                        			 
                        			 }else
                        			 {
                        			 	alert("上传文件格式不对，请重新导入！");
                        			 	return ;
                        			 }
                        			formimport.action="./DianboServlet?method=importDianboSubmit&realImagePath="+lastFileName;
                        			formimport.submit();
                        		}
                        	</script>
                      </tr>
                        </table>
                        </form>
				</div>
				<div class="tabs-panel">
				    <form id="formadd" name="formadd"    method="post" action="">
                	<table width="100%" class="datalist">
                	<tr>
                		<td class="tc">选择点播类型</td>
                		<td>
												<select id="dianbotypeadd" name="dianbotypeadd">
													<option value="0">
													请选择
													</option>
													 <%
													 if(dianboTypeList!=null&&dianboTypeList.size()>0){
														for(int t=0;t<dianboTypeList.size();t++){
															DianboType diaobotype=dianboTypeList.get(t);
														%>
														<option value="<%=diaobotype.getTypeId() %>">
														  <%=diaobotype.getTypeName() %>
														</option>
															<%
														}	 
														}
													 %>
												
												</select>
												</td>
                	</tr>
                      <tr>
                        <td  class="tc">新增点播信息：</td>
                        <td>
                           <input  type="text" id="Dianbocontent" size="50"  name="Dianbocontent" value="" />
                        </td>
                        </tr>
                        <tr>
                        <th scope="row"></th>
                        <td><input type="button" onclick="addDianbo()" value=" 提  交 " /></td>
                        	<script type="text/javascript">
                        	//验证上传格式
                        	function addDianbo(){
                        			var Dianbocontent = document.getElementById("Dianbocontent").value;
                        			var dianbotypeadd=document.getElementById("dianbotypeadd");
                        			var selText= dianbotypeadd.options[dianbotypeadd.selectedIndex].text;   
                        			if(Dianbocontent.length==0)
                        			{
                        				alert("点播信息内容不能为空，请重新添加！");
                        				return;
                        			 } 
                       			    if(selText=='请选择'){
                       			    	alert("请选择点播类型，再进行添加数据！");
                        				return;
                           			 }
                        			formadd.action="./DianboServlet?method=addDianboSubmit";
                        			formadd.submit();
                        		}
                        	</script>
                      </tr>
                        </table>
                        </form>
				</div>
		</div>
	</div>

		
		</section>
		</div>
		  <jsp:include page="../foot.jsp"></jsp:include>
	</body>
</html>
